package com.money.tracker.auth.enums;

import cn.hutool.captcha.generator.CodeGenerator;
import cn.hutool.captcha.generator.RandomGenerator;
import com.money.tracker.common.enums.IResponseEnum;
import com.money.tracker.common.exception.MoneyTrackerBizException;
import com.money.tracker.generator.UnsignedMathGenerator;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Objects;


/**
 * <p>
 *
 * <p>
 *
 * @author zhangshuai
 * &#064;@date 2024/09/21
 */
@Getter
@AllArgsConstructor
public enum CaptchaTypeEnum {

    /**
     * 数字
     */
    MATH(UnsignedMathGenerator.class),

    /**
     * 字符
     */
    CHAR(RandomGenerator.class);


    private final Class<? extends CodeGenerator> clazz;


    public static CodeGenerator getCodeGenerator(CaptchaTypeEnum type, Integer value) {
        if (Objects.equals(type, MATH)) {
            return new UnsignedMathGenerator(value);
        }
        if (Objects.equals(type, CHAR)) {
            return new RandomGenerator(value);
        }
        throw new MoneyTrackerBizException(IResponseEnum.UNKNOWN_VERIFICATION_CODE_TYPE);
    }

}
